package org.htmlparser.scanners;

import [C;
import org.htmlparser.lexer.Cursor;
import org.htmlparser.lexer.Page;
import org.htmlparser.util.ParserException;

public class ScriptDecoder
{
  public static int LAST_STATE = 0;
  protected static final int STATE_CHECKSUM = 6;
  protected static final int STATE_DECODE = 4;
  public static final int STATE_DONE = 0;
  protected static final int STATE_ESCAPE = 5;
  protected static final int STATE_FINAL = 7;
  public static final int STATE_INITIAL = 1;
  protected static final int STATE_LENGTH = 2;
  protected static final int STATE_PREFIX = 3;
  protected static int[] mDigits;
  protected static byte[] mEncodingIndex;
  protected static char[] mEscaped;
  protected static char[] mEscapes;
  protected static char[] mLeader;
  protected static char[][] mLookupTable;
  protected static char[] mPrefix;
  protected static char[] mTrailer;

  static
  {
    byte[] arrayOfByte = new byte[64];
    arrayOfByte[0] = 1;
    arrayOfByte[1] = 2;
    arrayOfByte[2] = 0;
    arrayOfByte[3] = 1;
    arrayOfByte[4] = 2;
    arrayOfByte[5] = 0;
    arrayOfByte[6] = 2;
    arrayOfByte[7] = 0;
    arrayOfByte[8] = 0;
    arrayOfByte[9] = 2;
    arrayOfByte[10] = 0;
    arrayOfByte[11] = 2;
    arrayOfByte[12] = 1;
    arrayOfByte[13] = 0;
    arrayOfByte[14] = 2;
    arrayOfByte[15] = 0;
    arrayOfByte[16] = 1;
    arrayOfByte[17] = 0;
    arrayOfByte[18] = 2;
    arrayOfByte[19] = 0;
    arrayOfByte[20] = 1;
    arrayOfByte[21] = 1;
    arrayOfByte[22] = 2;
    arrayOfByte[23] = 0;
    arrayOfByte[24] = 0;
    arrayOfByte[25] = 2;
    arrayOfByte[26] = 1;
    arrayOfByte[27] = 0;
    arrayOfByte[28] = 2;
    arrayOfByte[29] = 0;
    arrayOfByte[30] = 0;
    arrayOfByte[31] = 2;
    arrayOfByte[32] = 1;
    arrayOfByte[33] = 1;
    arrayOfByte[34] = 0;
    arrayOfByte[35] = 2;
    arrayOfByte[36] = 0;
    arrayOfByte[37] = 2;
    arrayOfByte[38] = 0;
    arrayOfByte[39] = 1;
    arrayOfByte[40] = 0;
    arrayOfByte[41] = 1;
    arrayOfByte[42] = 1;
    arrayOfByte[43] = 2;
    arrayOfByte[44] = 0;
    arrayOfByte[45] = 1;
    arrayOfByte[46] = 0;
    arrayOfByte[47] = 2;
    arrayOfByte[48] = 1;
    arrayOfByte[49] = 0;
    arrayOfByte[50] = 2;
    arrayOfByte[51] = 0;
    arrayOfByte[52] = 1;
    arrayOfByte[53] = 1;
    arrayOfByte[54] = 2;
    arrayOfByte[55] = 0;
    arrayOfByte[56] = 0;
    arrayOfByte[57] = 1;
    arrayOfByte[58] = 1;
    arrayOfByte[59] = 2;
    arrayOfByte[60] = 0;
    arrayOfByte[61] = 1;
    arrayOfByte[62] = 0;
    arrayOfByte[63] = 2;
    mEncodingIndex = arrayOfByte;
    [C[] arrayOf[C = new char[3][];
    char[] arrayOfChar1 = new char[97];
    arrayOfChar1[0] = 123;
    arrayOfChar1[1] = 50;
    arrayOfChar1[2] = 48;
    arrayOfChar1[3] = 33;
    arrayOfChar1[4] = 41;
    arrayOfChar1[5] = 91;
    arrayOfChar1[6] = 56;
    arrayOfChar1[7] = 51;
    arrayOfChar1[8] = 61;
    arrayOfChar1[9] = 88;
    arrayOfChar1[10] = 58;
    arrayOfChar1[11] = 53;
    arrayOfChar1[12] = 101;
    arrayOfChar1[13] = 57;
    arrayOfChar1[14] = 92;
    arrayOfChar1[15] = 86;
    arrayOfChar1[16] = 115;
    arrayOfChar1[17] = 102;
    arrayOfChar1[18] = 78;
    arrayOfChar1[19] = 69;
    arrayOfChar1[20] = 107;
    arrayOfChar1[21] = 98;
    arrayOfChar1[22] = 89;
    arrayOfChar1[23] = 120;
    arrayOfChar1[24] = 94;
    arrayOfChar1[25] = 125;
    arrayOfChar1[26] = 74;
    arrayOfChar1[27] = 109;
    arrayOfChar1[28] = 113;
    arrayOfChar1[29] = 0;
    arrayOfChar1[30] = 96;
    arrayOfChar1[31] = 0;
    arrayOfChar1[32] = 83;
    arrayOfChar1[33] = 0;
    arrayOfChar1[34] = 66;
    arrayOfChar1[35] = 39;
    arrayOfChar1[36] = 72;
    arrayOfChar1[37] = 114;
    arrayOfChar1[38] = 117;
    arrayOfChar1[39] = 49;
    arrayOfChar1[40] = 55;
    arrayOfChar1[41] = 77;
    arrayOfChar1[42] = 82;
    arrayOfChar1[43] = 34;
    arrayOfChar1[44] = 84;
    arrayOfChar1[45] = 106;
    arrayOfChar1[46] = 71;
    arrayOfChar1[47] = 100;
    arrayOfChar1[48] = 45;
    arrayOfChar1[49] = 32;
    arrayOfChar1[50] = 127;
    arrayOfChar1[51] = 46;
    arrayOfChar1[52] = 76;
    arrayOfChar1[53] = 93;
    arrayOfChar1[54] = 126;
    arrayOfChar1[55] = 108;
    arrayOfChar1[56] = 111;
    arrayOfChar1[57] = 121;
    arrayOfChar1[58] = 116;
    arrayOfChar1[59] = 67;
    arrayOfChar1[60] = 38;
    arrayOfChar1[61] = 118;
    arrayOfChar1[62] = 37;
    arrayOfChar1[63] = 36;
    arrayOfChar1[64] = 43;
    arrayOfChar1[65] = 40;
    arrayOfChar1[66] = 35;
    arrayOfChar1[67] = 65;
    arrayOfChar1[68] = 52;
    arrayOfChar1[69] = 9;
    arrayOfChar1[70] = 42;
    arrayOfChar1[71] = 68;
    arrayOfChar1[72] = 63;
    arrayOfChar1[73] = 119;
    arrayOfChar1[74] = 59;
    arrayOfChar1[75] = 85;
    arrayOfChar1[76] = 105;
    arrayOfChar1[77] = 97;
    arrayOfChar1[78] = 99;
    arrayOfChar1[79] = 80;
    arrayOfChar1[80] = 103;
    arrayOfChar1[81] = 81;
    arrayOfChar1[82] = 73;
    arrayOfChar1[83] = 79;
    arrayOfChar1[84] = 70;
    arrayOfChar1[85] = 104;
    arrayOfChar1[86] = 124;
    arrayOfChar1[87] = 54;
    arrayOfChar1[88] = 112;
    arrayOfChar1[89] = 110;
    arrayOfChar1[90] = 122;
    arrayOfChar1[91] = 47;
    arrayOfChar1[92] = 95;
    arrayOfChar1[93] = 75;
    arrayOfChar1[94] = 90;
    arrayOfChar1[95] = 44;
    arrayOfChar1[96] = 87;
    arrayOf[C[0] = arrayOfChar1;
    char[] arrayOfChar2 = new char[97];
    arrayOfChar2[0] = 87;
    arrayOfChar2[1] = 46;
    arrayOfChar2[2] = 71;
    arrayOfChar2[3] = 122;
    arrayOfChar2[4] = 86;
    arrayOfChar2[5] = 66;
    arrayOfChar2[6] = 106;
    arrayOfChar2[7] = 47;
    arrayOfChar2[8] = 38;
    arrayOfChar2[9] = 73;
    arrayOfChar2[10] = 65;
    arrayOfChar2[11] = 52;
    arrayOfChar2[12] = 50;
    arrayOfChar2[13] = 91;
    arrayOfChar2[14] = 118;
    arrayOfChar2[15] = 114;
    arrayOfChar2[16] = 67;
    arrayOfChar2[17] = 56;
    arrayOfChar2[18] = 57;
    arrayOfChar2[19] = 112;
    arrayOfChar2[20] = 69;
    arrayOfChar2[21] = 104;
    arrayOfChar2[22] = 113;
    arrayOfChar2[23] = 79;
    arrayOfChar2[24] = 9;
    arrayOfChar2[25] = 98;
    arrayOfChar2[26] = 68;
    arrayOfChar2[27] = 35;
    arrayOfChar2[28] = 117;
    arrayOfChar2[29] = 0;
    arrayOfChar2[30] = 126;
    arrayOfChar2[31] = 0;
    arrayOfChar2[32] = 94;
    arrayOfChar2[33] = 0;
    arrayOfChar2[34] = 119;
    arrayOfChar2[35] = 74;
    arrayOfChar2[36] = 97;
    arrayOfChar2[37] = 93;
    arrayOfChar2[38] = 34;
    arrayOfChar2[39] = 75;
    arrayOfChar2[40] = 111;
    arrayOfChar2[41] = 78;
    arrayOfChar2[42] = 59;
    arrayOfChar2[43] = 76;
    arrayOfChar2[44] = 80;
    arrayOfChar2[45] = 103;
    arrayOfChar2[46] = 42;
    arrayOfChar2[47] = 125;
    arrayOfChar2[48] = 116;
    arrayOfChar2[49] = 84;
    arrayOfChar2[50] = 43;
    arrayOfChar2[51] = 45;
    arrayOfChar2[52] = 44;
    arrayOfChar2[53] = 48;
    arrayOfChar2[54] = 110;
    arrayOfChar2[55] = 107;
    arrayOfChar2[56] = 102;
    arrayOfChar2[57] = 53;
    arrayOfChar2[58] = 37;
    arrayOfChar2[59] = 33;
    arrayOfChar2[60] = 100;
    arrayOfChar2[61] = 77;
    arrayOfChar2[62] = 82;
    arrayOfChar2[63] = 99;
    arrayOfChar2[64] = 63;
    arrayOfChar2[65] = 123;
    arrayOfChar2[66] = 120;
    arrayOfChar2[67] = 41;
    arrayOfChar2[68] = 40;
    arrayOfChar2[69] = 115;
    arrayOfChar2[70] = 89;
    arrayOfChar2[71] = 51;
    arrayOfChar2[72] = 127;
    arrayOfChar2[73] = 109;
    arrayOfChar2[74] = 85;
    arrayOfChar2[75] = 83;
    arrayOfChar2[76] = 124;
    arrayOfChar2[77] = 58;
    arrayOfChar2[78] = 95;
    arrayOfChar2[79] = 101;
    arrayOfChar2[80] = 70;
    arrayOfChar2[81] = 88;
    arrayOfChar2[82] = 49;
    arrayOfChar2[83] = 105;
    arrayOfChar2[84] = 108;
    arrayOfChar2[85] = 90;
    arrayOfChar2[86] = 72;
    arrayOfChar2[87] = 39;
    arrayOfChar2[88] = 92;
    arrayOfChar2[89] = 61;
    arrayOfChar2[90] = 36;
    arrayOfChar2[91] = 121;
    arrayOfChar2[92] = 55;
    arrayOfChar2[93] = 96;
    arrayOfChar2[94] = 81;
    arrayOfChar2[95] = 32;
    arrayOfChar2[96] = 54;
    arrayOf[C[1] = arrayOfChar2;
    char[] arrayOfChar3 = new char[97];
    arrayOfChar3[0] = 110;
    arrayOfChar3[1] = 45;
    arrayOfChar3[2] = 117;
    arrayOfChar3[3] = 82;
    arrayOfChar3[4] = 96;
    arrayOfChar3[5] = 113;
    arrayOfChar3[6] = 94;
    arrayOfChar3[7] = 73;
    arrayOfChar3[8] = 92;
    arrayOfChar3[9] = 98;
    arrayOfChar3[10] = 125;
    arrayOfChar3[11] = 41;
    arrayOfChar3[12] = 54;
    arrayOfChar3[13] = 32;
    arrayOfChar3[14] = 124;
    arrayOfChar3[15] = 122;
    arrayOfChar3[16] = 127;
    arrayOfChar3[17] = 107;
    arrayOfChar3[18] = 99;
    arrayOfChar3[19] = 51;
    arrayOfChar3[20] = 43;
    arrayOfChar3[21] = 104;
    arrayOfChar3[22] = 81;
    arrayOfChar3[23] = 102;
    arrayOfChar3[24] = 118;
    arrayOfChar3[25] = 49;
    arrayOfChar3[26] = 100;
    arrayOfChar3[27] = 84;
    arrayOfChar3[28] = 67;
    arrayOfChar3[29] = 0;
    arrayOfChar3[30] = 58;
    arrayOfChar3[31] = 0;
    arrayOfChar3[32] = 126;
    arrayOfChar3[33] = 0;
    arrayOfChar3[34] = 69;
    arrayOfChar3[35] = 44;
    arrayOfChar3[36] = 42;
    arrayOfChar3[37] = 116;
    arrayOfChar3[38] = 39;
    arrayOfChar3[39] = 55;
    arrayOfChar3[40] = 68;
    arrayOfChar3[41] = 121;
    arrayOfChar3[42] = 89;
    arrayOfChar3[43] = 47;
    arrayOfChar3[44] = 111;
    arrayOfChar3[45] = 38;
    arrayOfChar3[46] = 114;
    arrayOfChar3[47] = 106;
    arrayOfChar3[48] = 57;
    arrayOfChar3[49] = 123;
    arrayOfChar3[50] = 63;
    arrayOfChar3[51] = 56;
    arrayOfChar3[52] = 119;
    arrayOfChar3[53] = 103;
    arrayOfChar3[54] = 83;
    arrayOfChar3[55] = 71;
    arrayOfChar3[56] = 52;
    arrayOfChar3[57] = 120;
    arrayOfChar3[58] = 93;
    arrayOfChar3[59] = 48;
    arrayOfChar3[60] = 35;
    arrayOfChar3[61] = 90;
    arrayOfChar3[62] = 91;
    arrayOfChar3[63] = 108;
    arrayOfChar3[64] = 72;
    arrayOfChar3[65] = 85;
    arrayOfChar3[66] = 112;
    arrayOfChar3[67] = 105;
    arrayOfChar3[68] = 46;
    arrayOfChar3[69] = 76;
    arrayOfChar3[70] = 33;
    arrayOfChar3[71] = 36;
    arrayOfChar3[72] = 78;
    arrayOfChar3[73] = 80;
    arrayOfChar3[74] = 9;
    arrayOfChar3[75] = 86;
    arrayOfChar3[76] = 115;
    arrayOfChar3[77] = 53;
    arrayOfChar3[78] = 97;
    arrayOfChar3[79] = 75;
    arrayOfChar3[80] = 88;
    arrayOfChar3[81] = 59;
    arrayOfChar3[82] = 87;
    arrayOfChar3[83] = 34;
    arrayOfChar3[84] = 109;
    arrayOfChar3[85] = 77;
    arrayOfChar3[86] = 37;
    arrayOfChar3[87] = 40;
    arrayOfChar3[88] = 70;
    arrayOfChar3[89] = 74;
    arrayOfChar3[90] = 50;
    arrayOfChar3[91] = 65;
    arrayOfChar3[92] = 61;
    arrayOfChar3[93] = 95;
    arrayOfChar3[94] = 79;
    arrayOfChar3[95] = 66;
    arrayOfChar3[96] = 101;
    arrayOf[C[2] = arrayOfChar3;
    mLookupTable = arrayOf[C;
    mDigits = new int[123];
    for (int i = 0; i < 26; ++i)
    {
      mDigits[(i + 65)] = i;
      mDigits[(i + 97)] = (i + 26);
    }
    for (int j = 0; j < 10; ++j)
      mDigits[(j + 48)] = (j + 52);
    mDigits[43] = 62;
    mDigits[47] = 63;
    char[] arrayOfChar4 = new char[4];
    arrayOfChar4[0] = 35;
    arrayOfChar4[1] = 64;
    arrayOfChar4[2] = 126;
    arrayOfChar4[3] = 94;
    mLeader = arrayOfChar4;
    char[] arrayOfChar5 = new char[2];
    arrayOfChar5[0] = 61;
    arrayOfChar5[1] = 61;
    mPrefix = arrayOfChar5;
    char[] arrayOfChar6 = new char[6];
    arrayOfChar6[0] = 61;
    arrayOfChar6[1] = 61;
    arrayOfChar6[2] = 94;
    arrayOfChar6[3] = 35;
    arrayOfChar6[4] = 126;
    arrayOfChar6[5] = 64;
    mTrailer = arrayOfChar6;
    char[] arrayOfChar7 = new char[5];
    arrayOfChar7[0] = 35;
    arrayOfChar7[1] = 38;
    arrayOfChar7[2] = 33;
    arrayOfChar7[3] = 42;
    arrayOfChar7[4] = 36;
    mEscapes = arrayOfChar7;
    char[] arrayOfChar8 = new char[5];
    arrayOfChar8[0] = 13;
    arrayOfChar8[1] = 10;
    arrayOfChar8[2] = 60;
    arrayOfChar8[3] = 62;
    arrayOfChar8[4] = 64;
    mEscaped = arrayOfChar8;
  }

  public static String Decode(Page paramPage, Cursor paramCursor)
    throws ParserException
  {
    char[] arrayOfChar1 = new char[6];
    StringBuffer localStringBuffer = new StringBuffer(1024);
    int i = 0;
    int j = 0;
    int k = 0;
    int l = 0;
    int i1 = 0;
    int i2 = 1;
    long l1 = 0L;
    int i3 = 0;
    long l2 = 0L;
    while (true)
    {
      int i20;
      while (true)
      {
        int i15;
        while (true)
        {
          int i14;
          while (true)
          {
            long l4;
            int i10;
            int i11;
            long l5;
            while (true)
            {
              int i7;
              while (true)
              {
                char c1;
                int i5;
                while (true)
                {
                  while (true)
                  {
                    while (true)
                    {
                      int i4;
                      while (true)
                      {
                        while (true)
                        {
                          while (true)
                          {
                            while (true)
                            {
                              while (true)
                              {
                                if (i2 == 0)
                                  break label952;
                                i4 = paramPage.getCharacter(paramCursor);
                                c1 = (char)i4;
                                if (65535 != i4)
                                  break;
                                if ((1 != i2) || (k != 0) || (j != 0) || (i != 0) || (i1 != 0) || (l != 0))
                                  throw new ParserException("illegal state for exit");
                                i2 = 0;
                              }
                              switch (i2)
                              {
                              default:
                                throw new ParserException("invalid state: " + i2);
                              case 1:
                                if (c1 != mLeader[k])
                                  break;
                                i20 = k + 1;
                                if (i20 != mLeader.length)
                                  break label1004;
                                k = 0;
                                i2 = 2;
                              case 2:
                              case 3:
                              case 4:
                              case 5:
                              case 6:
                              case 7:
                              }
                            }
                            for (int i16 = 0; k > 0; i16 = i19)
                            {
                              char[] arrayOfChar2 = mLeader;
                              int i17 = i16 + 1;
                              localStringBuffer.append(arrayOfChar2[i16]);
                              int i18 = k - 1;
                              int i19 = i17 + 1;
                              k = i18;
                            }
                            localStringBuffer.append(c1);
                          }
                          arrayOfChar1[j] = c1;
                          i15 = j + 1;
                          if (i15 < arrayOfChar1.length)
                            break label997;
                          long l6 = decodeBase64(arrayOfChar1);
                          if (0L > l6)
                            throw new ParserException("illegal length: " + l6);
                          j = 0;
                          i2 = 3;
                          l1 = l6;
                        }
                        if (c1 != mPrefix[i])
                          break;
                        i14 = i + 1;
                        if (i14 < mPrefix.length)
                          break label990;
                        i = 0;
                        i2 = 4;
                      }
                      throw new ParserException("illegal character encountered: " + c1 + " ('" + c1 + "')");
                      if ('@' == c1)
                      {
                        int i13 = i3;
                        i11 = 5;
                        l4 = l2;
                        i10 = i13;
                      }
                      while (true)
                      {
                        while (true)
                        {
                          l5 = l1 - 1L;
                          if (0L != l5)
                            break label971;
                          l1 = l5;
                          i2 = 6;
                          i3 = 0;
                          l2 = l4;
                        }
                        if (i4 < 128)
                        {
                          int i12;
                          if (i4 == 9)
                            i12 = 0;
                          while (true)
                          {
                            while (true)
                            {
                              char c2 = mLookupTable[mEncodingIndex[(i3 % 64)]][i12];
                              localStringBuffer.append(c2);
                              l4 = l2 + c2;
                              i10 = i3 + 1;
                              i11 = i2;
                            }
                            if (i4 < 32)
                              break;
                            i12 = i4 - 31;
                          }
                          throw new ParserException("illegal encoded character: " + i4 + " ('" + c1 + "')");
                        }
                        localStringBuffer.append(c1);
                        l4 = l2;
                        i10 = i3;
                        i11 = i2;
                      }
                      int i8 = 0;
                      for (int i9 = 0; i9 < mEscapes.length; ++i9)
                        if (c1 == mEscapes[i9])
                        {
                          i8 = 1;
                          c1 = mEscaped[i9];
                        }
                      if (i8 == 0)
                        throw new ParserException("unexpected escape character: " + c1 + " ('" + c1 + "')");
                      localStringBuffer.append(c1);
                      l4 = l2 + c1;
                      i10 = i3 + 1;
                      i11 = 4;
                      l5 = l1 - 1L;
                      if (0L != l5)
                        break label971;
                      l1 = l5;
                      i2 = 6;
                      i3 = 0;
                      l2 = l4;
                    }
                    arrayOfChar1[i1] = c1;
                    i7 = i1 + 1;
                    if (i7 < arrayOfChar1.length)
                      break label964;
                    long l3 = decodeBase64(arrayOfChar1);
                    if (l3 != l2)
                      throw new ParserException("incorrect checksum, expected " + l3 + ", calculated " + l2);
                    i1 = 0;
                    i2 = 7;
                    l2 = 0L;
                  }
                  if (c1 != mTrailer[l])
                    break;
                  i5 = l + 1;
                  if (i5 < mTrailer.length)
                    break label957;
                  int i6 = LAST_STATE;
                  l = 0;
                  i2 = i6;
                }
                throw new ParserException("illegal character encountered: " + c1 + " ('" + c1 + "')");
                label952: return localStringBuffer.toString();
                label957: l = i5;
              }
              label964: i1 = i7;
            }
            label971: l1 = l5;
            i2 = i11;
            i3 = i10;
            l2 = l4;
          }
          label990: i = i14;
        }
        label997: j = i15;
      }
      label1004: k = i20;
    }
  }

  protected static long decodeBase64(char[] paramArrayOfChar)
  {
    return (0L + (mDigits[paramArrayOfChar[0]] << 2) + (mDigits[paramArrayOfChar[1]] >> 4) + ((0xF & mDigits[paramArrayOfChar[1]]) << 12) + (mDigits[paramArrayOfChar[2]] >> 2 << 8) + ((0x3 & mDigits[paramArrayOfChar[2]]) << 22) + (mDigits[paramArrayOfChar[3]] << 16) + (mDigits[paramArrayOfChar[4]] << 2 << 24) + (mDigits[paramArrayOfChar[5]] >> 4 << 24));
  }
}